import { createStore } from 'vuex'

export default createStore({
  state: {
    loadingGlobal: false,
    navBarInfo: {
      title: '',
      show: false,
    },
    orderId: '',
    showPopup: false,

    // 需要缓存的组件列表
    cacheRouteList: []
  },
  mutations: {
    // 设置页面头
    setNavBar(state, newValue) {
      state.navBarInfo = newValue;
    },
    setOrderId(state, newValue) {
      state.orderId = newValue;
    },
    setShowPopup(state, newValue) {
      state.showPopup = newValue;
    },

    //添加缓存组件
    addCacheRoute(state, name) {
      state.cacheRouteList.push(name);
    },

    //删除缓存组件
    removeCacheRoute(state, name) {
      for (let i = state.cacheRouteList.length - 1; i >= 0; i--) {
        if (state.cacheRouteList[i] === name) {
          state.cacheRouteList.splice(i, 1);
        }
      }
    },
  },
  actions: {
  },
  modules: {
  }
})